<html><head>
  <script type="text/javascript">
    window._points = [];
    window._start = +new Date();
    window.userId = 1;
    window.couponId = 1;
    window.host = "http://192.168.40.6";
    window.saveMethod = "/api/pluginCouponResult/saveCouponResult";
    window.getCouponStatusInfo = "/api/pluginCouponResult/getCouponStatusInfo";
    window.getCouponResultForTmp = "/api/pluginCouponResult/getCouponResultForTmp";

    var ua = navigator.userAgent;

    var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
    isIphone =!ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
    isAndroid = ua.match(/(Android)\s+([\d.]+)/);
      window.isMobile = isIphone || isAndroid;

  </script>
  <title>领取优惠券</title>
  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta name="format-detection" content="telephone=no" charset="utf-8">
  <style>
    body{line-height:1.6;font-family:"Helvetica Neue","Hiragino Sans GB","Microsoft YaHei","微软雅黑","黑体",Arial,sans-serif;font-size:14px;margin:0}
    .group:after{content:".";display:block;height:0;font-size:0;clear:both;visibility:hidden}
    .l{float:left}
    .r{float:right}
    h4,p{margin:0;padding:0;font-weight:normal}
    .msg_card .card_content{position:relative;padding:21px 13px 21px 84px;font-size:20px;border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;-webkit-border-radius:5px 5px 0 0;color:#fff;font-weight:normal}
    .msg_card .card_content .logo{position:absolute;top:21px;left:13px;display:block;width:60px;height:60px;border-radius:30px;-moz-border-radius:30px;-webkit-border-radius:30px;padding-top:0;margin-top:0}
    .msg_card .card_content .deco{position:absolute;bottom:-1px;left:0;width:100%;height:5px;background-image:url(//res.wx.qq.com/bizmall/zh_CN/htmledition/images/cardticket/card_tpl_deco200a94.png);background-repeat:repeat-x;background-position:center center}
    .msg_card .store{font-size:14px;color:#fff}.msg_card .card_bottom{border-radius:0 0 5px 5px;-moz-border-radius:0 0 5px 5px;-webkit-border-radius:0 0 5px 5px;border:1px solid #e7e7eb;padding:10px 0;text-align:center}
    .msg_card .btn{display:inline-block;text-decoration:none;padding:0 25px;text-align:center;font-size:15px;height:32px;line-height:32px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px}
    .msg_card .btn.btn_primary{background-color:#04be02;color:#fff}
    .msg_card .btn.btn_disabled{background-color:#e6e7ec;color:#a5a6aa;border:1px solid #dadbe0}
    .msg_card .info_warning{text-align:center;padding:5px 0;color:#8d8d8d}
    .msg_card .card_content{border-top-left-radius:2px;-moz-border-radius-topleft:2px;-webkit-border-top-left-radius:2px;border-top-right-radius:2px;-moz-border-radius-topright:2px;-webkit-border-top-right-radius:2px}
    /*.msg_card .card_bottom{position:relative;border-width:0}*/
    .msg_card .card_bottom:before{content:" ";/*position:absolute;*/top:0;left:0;/*border:1px solid #e1e1e1*/;border-bottom-left-radius:4px;-moz-border-radius-bottomleft:4px;-webkit-border-bottom-left-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-bottomright:4px;-webkit-border-bottom-right-radius:4px;border-top:0;width:200%;height:200%;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-webkit-transform:scale(0.5);transform:scale(0.5);-webkit-transform-origin:0 0;transform-origin:0 0}
  </style>
<body>
<!--end-->
<div class="wrp">
  <div id="js_form" action="javascript:return false;" class="vote_box form vote_form">
    <div class="vote_form_inner">

      <div class="msg_card" id="js_getcard" data-cardid="pEl-4uH7nlIftwUqnkG4cCk3ezBU">
        <div class="card_content" style="background-color:#10AD61;">

          <img class="logo" id="js_logo_url" data-src="http://test22umake.oss-cn-beijing.aliyuncs.com/test/radioStation/949_logo.jpg" src="http://test22umake.oss-cn-beijing.aliyuncs.com/test/radioStation/949_logo.jpg">
          <div class="card_info">
            <h4 class="card_title" >优码客折扣券</h4>
            <p class="store" >优码客</p>
          </div>
          <div class="deco"></div>
        </div>
        <div class="card_bottom" id="card_bottom">
        </div>

      </div>


    </div>
  </div>
  <script type="text/javascript">
    var xmlHttp;
    var Interval,Interval2=null;
    var card_bottom = document.getElementById("card_bottom");
    initData();

    function initData() {
      getData(window.host + window.getCouponStatusInfo + "?couponId=" + window.couponId + "&userId=" + window.userId,
        function () {
          if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var result = xmlHttp.responseText; // 返回值
            // 处理返回值
            result = JSON.parse(result);
            if(Interval2 != null){
              clearTimeout(Interval2)
            }
            if (result.errorCode == 0 || result.errorCode == -1) {
              card_bottom.innerHTML = '<a class="btn btn_default btn_disabled" >' + result.msg + '</a>';
              if (result.errorCode == -1) {
                //小于60秒时再触发
                if(result.data < 60000) {
                  Interval2 = setTimeout(initData, result.data);
                }
              }
            } else {
              //判断
              if (window.isMobile) {
                card_bottom.innerHTML = '<a class="btn btn_default btn_primary" href="javascript:void(0);" onclick="getCoupon()">领取卡券</a>';
              } else {
                //pc端
                card_bottom.innerHTML = '<p class="info info_warning">请使用手机客户端领券</p>';
              }
            }
          }
        }
      )
    }

    function getCoupon(){
      getData(window.host+window.saveMethod+"?couponId="+window.couponId+"&userId="+window.userId,
        function (){
          if (xmlHttp.readyState==4 && xmlHttp.status==200){
            card_bottom.innerHTML = '<a class="btn btn_default btn_disabled" >排队抢券中</a>';
            Interval = setInterval(getCouponResult(),1000);
          }
        }
      )
    }

    function getData(url,callback){
      if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlHttp=new XMLHttpRequest();
      }else{// code for IE6, IE5
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlHttp.open("GET",url,true);
      xmlHttp.onreadystatechange=callback;//发送事件后，收到信息了调用函数
      xmlHttp.send();
    }

    function getCouponResult(){
      getData(window.host+window.getCouponResultForTmp+"?couponId="+window.couponId+"&userId="+window.userId,
        function (){
          if (xmlHttp.readyState==4 && xmlHttp.status==200){
            clearInterval(Interval)
            var result =xmlHttp.responseText; // 返回值
            // 处理返回值
            result = JSON.parse(result);
            var data = result.data;
            if(data.key == 1){
              card_bottom.innerHTML = '<a class="btn btn_default btn_primary" href="javascript:void(0);" onclick="getCoupon()">'+data.text+'</a>';
            }else{
              card_bottom.innerHTML = '<a class="btn btn_default btn_disabled">'+data.text+'</a>';
            }
            alert(data.value);
          }
        }
      )
    }



  </script>
</div>
</body>
</html>
